

<html>
	<head>
		<title></title>
		<link rel="stylesheet" href="style.css">
		<script src="jquery-1.11.0.js"></script>
		<script src="gen.js"></script>
		<script>
			//makes a synchronous call to the page u and return the 
			//result as object
			var vid;
			function syncAjax(u){
				var obj=$.ajax(
					{url:u,
					 async:false
					 }
				);
				return $.parseJSON(obj.responseText);
				
			}
			function edit(obj,id){
				var r=getsubdistrict(id);
				vid=id;
				if(r.result==0){
					//show error message
					return;
				}
				//get the data from object r and put it in the form
				$("#vaccine_name").prop("value", ""+r.vaccine_name);
				
				//show the form
				//find where the user clicked and store it in x and y
				var y=event.clientY;
				var x=event.clientX/2;
				//use x and y to set the location of the form
				$("#divEdit").css("top",y);
				$("#divEdit").css("left",x);
				//display the form
				$("#divEdit").fadeIn(1000);
			}
			//returns a result object for one vaccine 
			function getsubdistrict(id){
				var u="subdistrict_action.php?cmd=1&id="+id;
				return syncAjax(u);
			}
			//makes asynchronous call to the save page
			function save(){
				//complete the url
				var sn = documment.getElementBy(id);
				var u="vaccine_action.php?cmd=2&vid="+r.vaccine_id+"&vn="+r.vaccine_name;
				$.getJSON(u,saveDone);
				
				cancel();
			}
			
			function saveDone(data){
				
				//alert(data);
				$("#divEdit").fadeOut(500);
			}
			//hides the form
			function cancel(){
				//fade out the form in half a second
				$("#divEdit").fadeOut(500);
			}
		</script>
		</head>
	<body>
		<table>
			<tr>
				<td colspan="2" id="pageheader">
					Health Information System
				</td>
			</tr>
			<tr>
				<td id="mainnav">
					<div class="menuitem">location</div>
					<div class="menuitem">opd cases</div>
					<div class="menuitem">health promotion</div>
					<div class="menuitem">nutrition</div>
					<div class="menuitem">child welfare</div>
					<div class="menuitem">family planning</div>
					<div class="menuitem"><a href="logout.php">logout<a></div>
				</td>
				<td id="content">
					<div id="divPageMenu">
						<span class="menuitem" ><a href="index_users.php">Users</a></span>
						<span class="menuitem" ><a href="index_community_list.php">Communities</a></span>
						<span class="menuitem" ><a href="index_subdistrict_list.php">Sub districts</a></span>
						<span class="menuitem" ><a href="index_district_list.php">Districts</a></span>
						<input type="text" id="txtSearch">
						<span class="menuitem">search</span>		
					</div>
					<div id="divStatus" class="status">
	
					</div>
					<div id="divContent">
				
						<!-- <table class="reportTable" width="100%" >
							<tr class="header" >
								<td>ID</td>
								<td>District Name</td>
								<td>District Capital</td>
							
								<td>Edit</td>
								<td>Delete</td>
							</tr> -->


						<table class="reportTable" width="100%" >
							<tr class="header" >
								<td>Subdistrict ID</td>
								<td>Subdistrict Name</td>
								<td>District ID</td>
								<td>Edit</td>
								<td>Delete</td>
							</tr>
<?php	
	include("subdistrict.php");
	$obj=new subdistrict();
	
	if(isset($_REQUEST['id'])){
		$subdistrict_id=$_REQUEST["id"];
		$obj->delete_community($subdistrict_id);
	}
	if(!$obj->get_all_subdistrict()){
		echo "error";
		exit();
	}
	
	$row=$obj->fetch();
	$row_counter=0;
	while($row){
		
		if($row_counter%2==0){
			$style=" class='row1' ";
		}else{
			$style=" class='row2'  ";
		}	
		$id=$row['subdistrict_id'];
		echo "<tr $style >";
			echo "<td>$id</td>";
			echo "<td>".$row['subdistrict_name']."</td>";
			echo "<td>".$row['district_id']."</td>";
			echo "<td><a href='index_update_subdistrict.php?id=$id'>Edit<a></td>";
			echo "<td><a href='index_subdistrict_list.php?id=$id'onclick='return confirm("."\"Are you sure you want to delete sub-district?\"".")'>Delete<a></td>";
		echo "</tr>";
		$row=$obj->fetch();
		$row_counter++;
	}
?>
						</table>
					</div>
				</td>
			</tr>
		</table>	
	</body>
</html>	